import request from "../../utils/request"
import {setToken} from "../../utils/token"



// initial state


const state = () => ({
  nickName:'',
  phone: false,
  avatar: false,
  // is_business: null,
  is_business:'yes',
  openid:''
})

// actions
const actions = {

  // getPhone(){
  //   request
  // }

  getUserInfo(context, payload) { // 更新用户信息
    console.log("准备获取个人用户信息");
    return new Promise((resolve, reject) => {
      console.log(payload, 'get')
      
      request('post', '/api/weixin/get_openid.htm', payload).then((res) => {
        console.log('获取个人用户信息')
        console.log(res, 'payload2')
        context.commit('setOpenid', res.openid)
        setToken( res.openid)
        context.commit('setIsBusiness', res.is_business);
      })
      // ToolClass.WxRequest({
      //   url: Api.UpdateUserInfo.url,
      //   method: Api.UpdateUserInfo.method,
      //   ...payload,
      //   success (res) {
      //     resolve(res)
      //   },
      //   error (res) {
      //     reject(res)
      //   }
      // })
    })
  },

}

// mutations
const mutations = {

  setNickName(state, states) {
    console.log(states,'userinfo5')
    state.nickName = states
  },
  setPhone(state, states) {
    
    state.phone = states
  },

  setAvatar(state, states) {
    state.avatar = states
  },
  setOpenid(state, states) {
    state.openid = states
  },
  
  setIsBusiness(state, states) {
    // setIsBusiness
    console.log(states)
    // state.is_business = states
  }
}

export default {
  namespaced: true,
  state,
  actions,
  mutations
}
